package com.apple.swing;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;
import android.widget.ToggleButton;

public class ControlActivity extends Activity implements OnClickListener {
	private ToggleButton tb;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.control_activity);
		
		tb = (ToggleButton) findViewById(R.id.swingbtn);
		tb.setOnClickListener(this);
		
		if(new Util().getSharedPerferences(getApplicationContext(), "swing.data", "swing", "").equals("ok")){
			tb.setChecked(true);
		}else {
			tb.setChecked(false);
		}
	}

	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.swingbtn:
			if(tb.isChecked()){
				new Util().writeSharedPerferences(getApplicationContext(),"swing.data","swing", "ok");
				Toast.makeText(getApplicationContext(), "Swing Mode", Toast.LENGTH_SHORT).show();
			}else {
				new Util().writeSharedPerferences(getApplicationContext(), "swing.data", "swing", "no");
			}
			
			break;
		}
	}
}
